import 'package:enterprise_v6_app/generated/json/base/json_convert_content.dart';
import 'package:enterprise_v6_app/app/data/entities/common/department_tree_entity.dart';
import 'package:enterprise_v6_app/app/data/common/choice_bean.dart';

import 'package:enterprise_v6_app/app/data/entities/common/department_user_entity.dart';


DepartmentTreeEntity $DepartmentTreeEntityFromJson(Map<String, dynamic> json) {
  final DepartmentTreeEntity departmentTreeEntity = DepartmentTreeEntity();
  final String? pid = jsonConvert.convert<String>(json['pid']);
  if (pid != null) {
    departmentTreeEntity.pid = pid;
  }
  final List<DepartmentTreeEntity>? children = (json['children'] as List<dynamic>?)?.map(
          (e) => jsonConvert.convert<DepartmentTreeEntity>(e) as DepartmentTreeEntity).toList();
  if (children != null) {
    departmentTreeEntity.children = children;
  }
  final String? departmentName = jsonConvert.convert<String>(json['departmentName']);
  if (departmentName != null) {
    departmentTreeEntity.departmentName = departmentName;
  }
  final String? id = jsonConvert.convert<String>(json['id']);
  if (id != null) {
    departmentTreeEntity.id = id;
  }
  final bool? isExpand = jsonConvert.convert<bool>(json['isExpand']);
  if (isExpand != null) {
    departmentTreeEntity.isExpand = isExpand;
  }
  final bool? isSelected = jsonConvert.convert<bool>(json['isSelected']);
  if (isSelected != null) {
    departmentTreeEntity.isSelected = isSelected;
  }
  final List<DepartmentUserEntity>? userList = (json['userList'] as List<dynamic>?)?.map(
          (e) => jsonConvert.convert<DepartmentUserEntity>(e) as DepartmentUserEntity).toList();
  if (userList != null) {
    departmentTreeEntity.userList = userList;
  }
  return departmentTreeEntity;
}

Map<String, dynamic> $DepartmentTreeEntityToJson(DepartmentTreeEntity entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['pid'] = entity.pid;
  data['children'] = entity.children?.map((v) => v.toJson()).toList();
  data['departmentName'] = entity.departmentName;
  data['id'] = entity.id;
  data['isExpand'] = entity.isExpand;
  data['isSelected'] = entity.isSelected;
  data['userList'] = entity.userList?.map((v) => v.toJson()).toList();
  return data;
}

extension DepartmentTreeEntityExtension on DepartmentTreeEntity {
  DepartmentTreeEntity copyWith({
    String? pid,
    List<DepartmentTreeEntity>? children,
    String? departmentName,
    String? id,
    bool? isExpand,
    bool? isSelected,
    List<DepartmentUserEntity>? userList,
  }) {
    return DepartmentTreeEntity()
      ..pid = pid ?? this.pid
      ..children = children ?? this.children
      ..departmentName = departmentName ?? this.departmentName
      ..id = id ?? this.id
      ..isExpand = isExpand ?? this.isExpand
      ..isSelected = isSelected ?? this.isSelected
      ..userList = userList ?? this.userList;
  }
}
